package huawei;

import java.util.*;

public class Test001 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String str = in.next();
            str =  str.substring(2, str.length());
            cover(str);
        }
    }

    private static void cover(String str) {
        int len = str.length();
        HashMap<String, Integer> map = new HashMap<>();
        for (int i = 0; i < 10; i++) {
            map.put(i + "", i);
        }
        map.put("A", 10);
        map.put("B", 11);
        map.put("C", 12);
        map.put("D", 13);
        map.put("E", 14);
        map.put("F", 15);
        int res = 0;
        int len2 = len - 1;
        for (int i = 0; i < len; i++) {
            String s = str.charAt(i) + "";
            int num = map.get(s);
            res += num  * 16;
            len2--;
        }
        System.out.println(res);
    }
}
